package com.Web.Service.Impl;

import com.Web.DAO.ITeacherDAO;
import com.Web.DAO.Impl.TeacherDAOImpl;
import com.Web.Person.Teacher;
import com.Web.Service.ITeacherService;
import com.Web.util.PageInfo;

import java.util.List;

public class TeacherServiceImpl implements ITeacherService {

    private ITeacherDAO teacherDAO = new TeacherDAOImpl();

    @Override
    public PageInfo<Teacher> selectByPage(Integer pageNo, Integer pageSize) {
        int offset = (pageNo - 1) * pageSize;
        List<Teacher> list = teacherDAO.selectByPage(offset, pageSize);
        int totalCount = teacherDAO.selectTotalCount();
        int totalPage = (int)Math.ceil((double)totalCount / pageSize);
        PageInfo pageInfo = new PageInfo(list, totalPage, pageNo, pageSize);
        return pageInfo;
    }

    @Override
    public List<Teacher> selectAll() {
        List<Teacher> list = teacherDAO.selectAll();
        return list;
    }

    @Override
    public void deleteById(int i) {
        teacherDAO.deleteById(i);
    }

    @Override
    public void add(Teacher teacher) {
        teacherDAO.add(teacher);
    }

    @Override
    public Teacher toUpDate(int id) {
        Teacher teacher = teacherDAO.toUpDate(id);
        return teacher;
    }

    @Override
    public void update(Teacher teacher) {
        teacherDAO.update(teacher);
    }
}
